﻿using CRM.Admin.Contracts.Contract.Customer;
using CRM.Admin.Contracts.Model.Map;
using KingsSharp.Core;
using KingsSharp.Core.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CRM.Admin.Contracts.Dto.Customer;
using KingsSharp.Common.Data;
using KingsSharp.Common;

namespace CRM.Admin.Services.Service.Customer
{
    /// <summary>
    /// 销售流向
    /// </summary>
    public class SaleService : ServiceBase, ISaleService
    {
        private IRepository<SaleInfo, Guid> saleRepository;
        public SaleService(IRepository<SaleInfo, Guid> _saleRepository)
            :base(_saleRepository.UnitOfWork)
        {
            saleRepository = _saleRepository;
        }

        public IQueryable<SaleInfo> Sales
        {
            get
            {
                return saleRepository.Entities;
            }
        }

        public OperationResult Insert(params SaleDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            foreach (var t in dtos)
            {
                t.Id = Guid.NewGuid();
                t.CreateTime = DateTime.Now;

            }
            var result = saleRepository.Insert(dtos);
            return result;
        }
    }
}
